/**
 * @program: LeetCode
 * @description: LeetCode : 222.完全二叉树的节点个数
 * @author: WXY
 * @create: 2023-01-16 19:30
 * @Version 1.0
 **/
public class Num222_countNodes {
    public int countNodes(TreeNode root) {
        return process(root);
    }

    private int process(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftNum = process(root.left);
        int rightNum = process(root.right);
        int num = 1 + leftNum + rightNum;
        return num;
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
